<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTablePermissions extends Migration {

    /**
     * RBAC权限
     */
    public function up() {

        //角色表
        Schema::create('role', function (Blueprint $table) {
            $table->increments('id')->unsigned();
            $table->string('role_name', 80)->comment("角色名称");
            $table->string('role_explain', 80)->comment("角色名称");
            $table->timestamps();
        });

        //角色用户关系表
        Schema::create('role_user', function (Blueprint $table) {
            $table->increments('id')->unsigned();
            $table->integer('userid')->comment("用户id");
            $table->integer('roleid')->comment("角色id");
            $table->timestamps();
        });
        //权限表
        Schema::create('permissions', function (Blueprint $table) {
            $table->increments('id')->unsigned();
            $table->integer('pid')->default(0)->nullable()->index('pid')->comment('父级ID');
            $table->string('permissions_name', 80)->comment("权限名称");
            $table->string('urls', 500)->default('#')->comment('路由');
            $table->string('method', 20)->default('GET')->comment('请求方式');
            $table->string('icon', 32)->default('')->nullable()->comment('图标');
            $table->string('params', 300)->nullable()->comment('参数');
            $table->tinyInteger('sort')->default(0)->comment("排序");
            $table->tinyInteger('is_show')->default(0)->comment("是否显示 0显示，1不显示 ");
            $table->tinyInteger('is_menus')->default(1)->comment("是否菜单 0是，1否 ");
            $table->string('permissions_explain', 80)->nullable()->default('')->comment("权限说明");
            $table->timestamps();
        });
        //权限与角色关系表
        Schema::create('role_permissions', function (Blueprint $table) {
            $table->increments('id')->unsigned();
            $table->integer('roleid')->comment("角色id");
            $table->integer('permissionsid')->comment("权限id");
            $table->timestamps();
        });
    }

    public function down() {
        Schema::dropIfExists('role');
        Schema::dropIfExists('role_user');
        Schema::dropIfExists('permissions');
        Schema::dropIfExists('role_permissions');
        Schema::dropIfExists('menus_user');
    }

}
